<?php

namespace Sharks\Core\Http\Form;

use Sharks\Core\Http\Request;
use Sharks\Core\Support\Base\Str;

/**
 * 查询参数类
 */
class QueryParam {


    private $name;
    private $request;

    public function __construct($name, Request $request) {
        $this->name = $name;
        $this->request = $request;
    }   

    /**
     * name: query.{$name}
     */
    public function getValue($default = null) {
        return $this->request->query("query_param_" . $this->name, $default);
    }

    /**
     * name: related.{name}.{identifier}
     * example:
     * <pre>
     * between:
     *  <input name="related.createdate.start" value="..." /> // getRelatedValue("start")
     *  <input name="related.createdate.end" value="..." /> // getRelatedValue("end")
     * </pre>
     */
    public function getRelatedValue($identifier, $default = null) {
        return $this->request->query("query_name_" . $this->name . "_" . $identifier, $default);
    }

    /**
     * name: way.{name}
     */
    public function getWay() {
        return $this->request->query("query_way_" . $this->name, self::WAY_EQUAL);
    }
}